From 3bedc40a365cf58ecb57e187b6739f940a033ea1 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Sun, 19 Oct 2014 19:04:27 +0000 Subject: [PATCH] Bring Qstrings to gt_find_desc_from_icon_number, and a few other places. --- gpsbabel/bcr.cc | 2 +- gpsbabel/compegps.cc | 2 +- gpsbabel/g7towin.cc | 8 +++----- gpsbabel/garmin.cc | 3 +-- gpsbabel/garmin_tables.cc | 21 +++++---------------- gpsbabel/garmin_tables.h | 2 +- gpsbabel/garmin_txt.cc | 14 ++++---------- gpsbabel/gdb.cc | 4 ++-- gpsbabel/lowranceusr.cc | 2 +- gpsbabel/mapsource.cc | 3 +-- gpsbabel/pcx.cc | 2 +- gpsbabel/psitrex.cc | 33 ++++++++++++--------------------- gpsbabel/tpg.cc | 4 ++-- 13 files changed, 35 insertions(+), 65 deletions(-) diff --git a/gpsbabel/bcr.cc b/gpsbabel/bcr.cc index d1e234717..d71d48a24 100644 --- a/gpsbabel/bcr.cc +++ b/gpsbabel/bcr.cc @@ -146,7 +146,7 @@ bcr_handle_icon_str(const char* str, Waypoint* wpt) wpt->description = m->symbol_DE; if (m->mps_name != NULL) { nr = gt_find_icon_number_from_desc(m->mps_name, MAPSOURCE); - wpt->icon_descr = gt_find_desc_from_icon_number(nr, MAPSOURCE, NULL); + wpt->icon_descr = gt_find_desc_from_icon_number(nr, MAPSOURCE); } return; } diff --git a/gpsbabel/compegps.cc b/gpsbabel/compegps.cc index d5ea38d1f..b6a57f3c1 100644 --- a/gpsbabel/compegps.cc +++ b/gpsbabel/compegps.cc @@ -500,7 +500,7 @@ write_waypt_cb(const Waypoint* wpt) } gbfprintf(fout, "\n"); - if ((wpt->icon_descr != NULL) || (wpt->wpt_flags.proximity) || \ + if ((!wpt->icon_descr.isNull()) || (wpt->wpt_flags.proximity) || \ (option_icon != NULL)) { gbfprintf(fout, "w %s,0,0.0,16777215,255,1,7,,%.1f\n", wpt->icon_descr.isNull() ? "Waypoint" : CSTR(wpt->icon_descr), diff --git a/gpsbabel/g7towin.cc b/gpsbabel/g7towin.cc index 7df56a125..cfbd5271d 100644 --- a/gpsbabel/g7towin.cc +++ b/gpsbabel/g7towin.cc @@ -89,7 +89,7 @@ parse_line(char* buff, int index, const char* delimiter, Waypoint* wpt) switch (index) { - int categories, dyn; + int categories; struct tm tm; char* cerr; @@ -114,7 +114,7 @@ parse_line(char* buff, int index, const char* delimiter, Waypoint* wpt) case WAYPT__OFS + 2: wpt->icon_descr = gt_find_desc_from_icon_number( - atoi(cin), PCX, &dyn); + atoi(cin), PCX); break; case WAYPT__OFS + 4: @@ -466,11 +466,9 @@ data_read(void) cdata++; } if (*cdata == ';') { - int dyn; - cdata++; wpt->icon_descr = gt_find_desc_from_icon_number( - atoi(cdata), PCX, &dyn); + atoi(cdata), PCX); } waypt_add(wpt); break; diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index bb629a452..bce743319 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -399,9 +399,8 @@ waypt_read(void) wpt_tmp->icon_descr = d103_symbol_from_icon_number( way[i]->smbl); } else { - int dyn = 0; wpt_tmp->icon_descr = gt_find_desc_from_icon_number( - way[i]->smbl, PCX, &dyn); + way[i]->smbl, PCX); } /* * If a unit doesn't store altitude info (i.e. a D103) diff --git a/gpsbabel/garmin_tables.cc b/gpsbabel/garmin_tables.cc index 40412879d..f08d201ed 100644 --- a/gpsbabel/garmin_tables.cc +++ b/gpsbabel/garmin_tables.cc @@ -731,29 +731,18 @@ gt_switch_display_mode_value(const unsigned char display_mode, const int protoid } } -const char* -gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format, int* dynamic) +const QString +gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format) { - icon_mapping_t* i; - char custom[] = "Custom 63 "; - if ((garmin_format == GDB) && (icon >= 500) && (icon <= 563)) { - snprintf(custom, sizeof(custom), "Custom %d", icon - 500); - *dynamic = 1; - return xstrdup(custom); + return QString("Custom %d").arg(icon - 500); } if ((garmin_format == PCX) && (icon >= 7680) && (icon <= 8191)) { - snprintf(custom, sizeof(custom), "Custom %d", icon - 7680); - *dynamic = 1; - return xstrdup(custom); + return QString("Custom %d").arg(icon - 7680); } - if (dynamic) { - *dynamic = 0; - } - - for (i = garmin_icon_table; i->icon; i++) { + for (icon_mapping_t* i = garmin_icon_table; i->icon; i++) { switch (garmin_format) { case MAPSOURCE: case GDB: diff --git a/gpsbabel/garmin_tables.h b/gpsbabel/garmin_tables.h index 2e2252909..8f2b13b9f 100644 --- a/gpsbabel/garmin_tables.h +++ b/gpsbabel/garmin_tables.h @@ -36,7 +36,7 @@ typedef struct icon_mapping { typedef enum {MAPSOURCE, PCX, GARMIN_SERIAL, GDB} garmin_formats_e; -const char* gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format, int* dynamic); +const QString gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format); int gt_find_icon_number_from_desc(const QString& desc, garmin_formats_e garmin_format); extern icon_mapping_t garmin_icon_table[]; diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index c88ed950e..4b5e33904 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -544,8 +544,7 @@ write_waypt(const Waypoint* wpt) const char* dspl_mode; const char* country; double x; - int i, icon, dynamic; - const char* icon_descr; + int i, icon; gmsd = GMSD_FIND(wpt); @@ -609,12 +608,7 @@ write_waypt(const Waypoint* wpt) if (icon == -1) { icon = gt_find_icon_number_from_desc(wpt->icon_descr, GDB); } - icon_descr = gt_find_desc_from_icon_number(icon, GDB, &dynamic); - print_string("%s\t", icon_descr); - if (dynamic) { - // sleaze alert: cast away constness. - xfree((char*) icon_descr); - } + print_string("%s\t", gt_find_desc_from_icon_number(icon, GDB)); print_string("%s\t", GMSD_GET(facility, "")); print_string("%s\t", GMSD_GET(city, "")); @@ -1126,7 +1120,7 @@ parse_waypoint(void) fs_chain_add(&wpt->fs, (format_specific_data*) gmsd); while ((str = csv_lineparse(NULL, "\t", "", column++))) { - int i, dynamic; + int i; double d; int field_no = header_fields[waypt_header][column]; @@ -1179,7 +1173,7 @@ parse_waypoint(void) case 11: i = gt_find_icon_number_from_desc(str, GDB); GMSD_SET(icon, i); - wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB, &dynamic); + wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB); break; case 12: GMSD_SETSTR(facility, str); diff --git a/gpsbabel/gdb.cc b/gpsbabel/gdb.cc index 929de7112..069857091 100644 --- a/gpsbabel/gdb.cc +++ b/gpsbabel/gdb.cc @@ -525,7 +525,7 @@ static Waypoint* read_waypoint(gt_waypt_classes_e* waypt_class_out) { char buf[128]; /* used for temporary stuff */ - int display, icon, dynamic; + int display, icon; gt_waypt_classes_e wpt_class; int i; Waypoint* res; @@ -744,7 +744,7 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) GMSD_SETSTR(postal_code, bufp); } - res->icon_descr = gt_find_desc_from_icon_number(icon, GDB, &dynamic); + res->icon_descr = gt_find_desc_from_icon_number(icon, GDB); #if GDB_DEBUG DBG(GDB_DBG_WPTe, icon != GDB_DEF_ICON) diff --git a/gpsbabel/lowranceusr.cc b/gpsbabel/lowranceusr.cc index 42cd8640b..d786d8ab2 100644 --- a/gpsbabel/lowranceusr.cc +++ b/gpsbabel/lowranceusr.cc @@ -253,7 +253,7 @@ lowranceusr_readstr(char* buf, const int maxlen, gbfile* file) return len; } -const char* +const QString lowranceusr_find_desc_from_icon_number(const int icon) { const lowranceusr_icon_mapping_t* i; diff --git a/gpsbabel/mapsource.cc b/gpsbabel/mapsource.cc index 166d51c32..0fb9f7955 100644 --- a/gpsbabel/mapsource.cc +++ b/gpsbabel/mapsource.cc @@ -520,7 +520,6 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, Waypoint** wpt, unsigned int* mpsc int lat; int lon; int icon; - int dynamic; Waypoint* thisWaypoint = NULL; double mps_altitude = unknown_alt; @@ -597,7 +596,7 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, Waypoint** wpt, unsigned int* mpsc } /* might need to change this to handle version dependent icon handling */ - thisWaypoint->icon_descr = gt_find_desc_from_icon_number(icon, MAPSOURCE, &dynamic); + thisWaypoint->icon_descr = gt_find_desc_from_icon_number(icon, MAPSOURCE); /* The following Now done elsewhere since it can be useful to read in and perhaps not add to the list */ diff --git a/gpsbabel/pcx.cc b/gpsbabel/pcx.cc index 6132b714d..7aff32e42 100644 --- a/gpsbabel/pcx.cc +++ b/gpsbabel/pcx.cc @@ -163,7 +163,7 @@ data_read(void) if (*cp != '\0') { wpt_tmp->description = cp; } - wpt_tmp->icon_descr = gt_find_desc_from_icon_number(symnum, PCX, NULL); + wpt_tmp->icon_descr = gt_find_desc_from_icon_number(symnum, PCX); if (read_as_degrees || read_gpsu) { human_to_dec(tbuf, &lat, &lon, 1); diff --git a/gpsbabel/psitrex.cc b/gpsbabel/psitrex.cc index ec4f83c2c..328733730 100644 --- a/gpsbabel/psitrex.cc +++ b/gpsbabel/psitrex.cc @@ -326,7 +326,7 @@ psit_waypoint_r(gbfile* psit_file, Waypoint** wpt) /* since PsiTrex only deals with Garmins, let's use the "proper" Garmin icon name */ /* convert the PsiTrex name to the number, which is the PCX one; from there to Garmin desc */ garmin_icon_num = psit_find_icon_number_from_desc(psit_current_token); - thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX, NULL); + thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX); waypt_add(thisWaypoint); @@ -448,7 +448,7 @@ psit_route_r(gbfile* psit_file, route_head** rte) /* since PsiTrex only deals with Garmins, let's use the "proper" Garmin icon name */ /* convert the PsiTrex name to the number, which is the PCX one; from there to Garmin desc */ garmin_icon_num = psit_find_icon_number_from_desc(psit_current_token); - thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX, NULL); + thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX); route_add_wpt(rte_head, thisWaypoint); @@ -472,7 +472,7 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte) { char hdr[20]; unsigned int rte_datapoints; - char* rname; + QString rname; Waypoint* testwpt; time_t uniqueValue = 0; @@ -501,18 +501,14 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte) /* route name */ if (rte->rte_name.isEmpty()) { - sprintf(hdr, "Route%04x", (unsigned) uniqueValue); - rname = xstrdup(hdr); + rname = QString("Route%1").arg((uint) uniqueValue, 4, 16, QChar('0')); } else { - rname = xstrdup(rte->rte_name); + rname = rte->rte_name; } /* check for psitrex comment sign; replace with '$' */ - while ((c = strchr(rname, '#'))) { - *c = '$'; - } + rname = rname.replace(QChar('#'), QChar('$')); - gbfprintf(psit_file, "Route: %s\n", rname); - xfree(rname); + gbfputs(QString("Route: %1\n").arg(rname), psit_file); } } @@ -633,7 +629,7 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk) { char hdr[30]; unsigned int trk_datapoints; - char* tname; + QString tname; Waypoint* testwpt; time_t uniqueValue = 0; @@ -659,20 +655,15 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk) /* track name */ if (trk->rte_name.isEmpty()) { - sprintf(hdr, "Track%04x", (unsigned) uniqueValue); - tname = xstrdup(hdr); + tname = QString("Track%1").arg((uint) uniqueValue, 4, 16, QChar('0')); } else { - tname = xstrdup(trk->rte_name); + tname = trk->rte_name; } /* check for psitrex comment sign; replace with '$' */ - while ((c = strchr(tname, '#'))) { - *c = '$'; - } - - gbfprintf(psit_file, "Track: %s\n", tname); + tname = tname.replace(QChar('#'), QChar('$')); - xfree(tname); + gbfputs(QString("Track: %1\n").arg(tname), psit_file); } } psit_track_state = 1; diff --git a/gpsbabel/tpg.cc b/gpsbabel/tpg.cc index 9db086a04..4655245f4 100644 --- a/gpsbabel/tpg.cc +++ b/gpsbabel/tpg.cc @@ -195,11 +195,11 @@ tpg_waypt_pr(const Waypoint* wpt) if (global_opts.synthesize_shortnames) { shortname = mkshort_from_wpt(mkshort_handle, wpt); } else { - shortname = xstrdup(wpt->description); + shortname = wpt->description; } } else { /* no description available */ - shortname = xstrdup(""); + shortname = ""; } } else { shortname = wpt->shortname; -- 2.30.2